<template>
    <van-nav-bar title="搜索" left-text="返回" left-arrow @click-left="() => { $router.push('/') }" />
    <div style="height: 45px;"></div>
    <van-search v-model="searchval" shape="round" background="#4fc08d" placeholder="请输入搜索关键词" />
    <van-skeleton v-show="gjp" title :row="10" />
    <van-cell-group v-for="item in qsearchApiData">
        <router-link :to="{ name: 'detail', params: { goods_id: item.goods_id } }">
            <van-cell :title="item.goods_name" />
        </router-link>
    </van-cell-group>
    <div class="status">
        9999999999999999999999999999999999
    </div>
    <van-empty v-show="kongstatus" image="https://fastly.jsdelivr.net/npm/@vant/assets/custom-empty-image.png"
        image-size="80" description="搜索空空" />
</template>

<script setup>
import { qsearchApi } from '@/api/api';
import _ from 'lodash';
import { ref, watch } from 'vue';
let qsearchApiData = ref([])
let searchval = ref('')
let status = ref(true)
let kongstatus = ref(false)
let gjp = ref(false)
watch(searchval, _.debounce(val => {
    if (val.length == 0) {
        status.value = true
        kongstatus.value = false
    } else {
        status.value = false
        qsearchApi(val).then(res => {
            gjp.value = true
            qsearchApiData.value = res.data.message
            if (res.data.message.length == 0) {
                kongstatus.value = true
            } else {
                kongstatus.value = false
            }
        })
    }
}, 3000))
setInterval(() => {
    gjp.value = false
}, 2000)
</script>

<style lang="scss" scoped></style>